{extend name="common@base/common" /}

{block name="style"}
<link href="__CSS__/main.min.css" rel="stylesheet" type="text/css"/>
<link href="__ZUI__/lib/tabs/zui.tabs.css" rel="stylesheet">
{/block}

{block name="body"}
<div class="container">
  <ol class="breadcrumb">
      <li><a href="{:url('index/index')}">演示首页</a></li>
      <li>标签页</li>
  </ol>
<section class="demo-section">
<div id="pageContent">

<section>
  <header><h3>综合示例</h3></header>
  <article>
    <div class="example">

  <div class="tabs" id="tabsExample">

  </div>
</div>
<pre class="prettyprint prettyprinted" style=""><code class="lang-html"><span class="tag">&lt;div</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"tabs"</span><span class="pln"> </span><span class="atn">id</span><span class="pun">=</span><span class="atv">"tabsExample"</span><span class="tag">&gt;&lt;/div&gt;</span></code></pre><pre class="prettyprint prettyprinted" style=""><code class="lang-js"><span class="com">// 定义标签页</span><span class="pln">
</span><span class="kwd">var</span><span class="pln"> tabs </span><span class="pun">=</span><span class="pln"> </span><span class="pun">[{</span><span class="pln">
    title</span><span class="pun">:</span><span class="pln"> </span><span class="str">'iframe 例子'</span><span class="pun">,</span><span class="pln">
    url</span><span class="pun">:</span><span class="pln"> </span><span class="str">'docs/partial/iframe-tab.html'</span><span class="pun">,</span><span class="pln">
    type</span><span class="pun">:</span><span class="pln"> </span><span class="str">'iframe'</span><span class="pun">,</span><span class="pln">
    forbidClose</span><span class="pun">:</span><span class="pln"> </span><span class="kwd">true</span><span class="pln">
</span><span class="pun">},</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
    title</span><span class="pun">:</span><span class="pln"> </span><span class="str">'Ajax 例子'</span><span class="pun">,</span><span class="pln">
    url</span><span class="pun">:</span><span class="pln"> </span><span class="str">'docs/partial/remote-tab.html'</span><span class="pun">,</span><span class="pln">
    type</span><span class="pun">:</span><span class="pln"> </span><span class="str">'ajax'</span><span class="pln">
</span><span class="pun">},</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
    title</span><span class="pun">:</span><span class="pln"> </span><span class="str">'自定义例子'</span><span class="pun">,</span><span class="pln">
    icon</span><span class="pun">:</span><span class="pln"> </span><span class="str">'icon-star'</span><span class="pun">,</span><span class="pln">
    type</span><span class="pun">:</span><span class="pln"> </span><span class="str">'custom'</span><span class="pun">,</span><span class="pln">
    content</span><span class="pun">:</span><span class="pln"> </span><span class="kwd">function</span><span class="pun">()</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
        </span><span class="kwd">return</span><span class="pln"> </span><span class="str">'&lt;div class="alert alert-block alert-success"&gt;&lt;p&gt;这里的内容是通过函数动态生成的，每次刷新下面的时间都会更新。&lt;/p&gt;&lt;p&gt;'</span><span class="pln"> </span><span class="pun">+</span><span class="pln"> </span><span class="pun">(</span><span class="kwd">new</span><span class="pln"> </span><span class="typ">Date</span><span class="pun">().</span><span class="pln">format</span><span class="pun">(</span><span class="str">'yyyy-MM-dd hh:mm:ss'</span><span class="pun">))</span><span class="pln"> </span><span class="pun">+</span><span class="pln">   </span><span class="str">'&lt;/p&gt;&lt;/div&gt;'</span><span class="pun">;</span><span class="pln">
    </span><span class="pun">}</span><span class="pln">
</span><span class="pun">},</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
    title</span><span class="pun">:</span><span class="pln"> </span><span class="str">'MZUI'</span><span class="pun">,</span><span class="pln">
    url</span><span class="pun">:</span><span class="pln"> </span><span class="str">'http://zui.sexy/m'</span><span class="pun">,</span><span class="pln">
    type</span><span class="pun">:</span><span class="pln"> </span><span class="str">'iframe'</span><span class="pln">
</span><span class="pun">},</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
    defaultTitle</span><span class="pun">:</span><span class="pln"> </span><span class="str">'无法加载的标签页'</span><span class="pun">,</span><span class="pln">
    url</span><span class="pun">:</span><span class="pln"> </span><span class="str">'http://zui1.sexy'</span><span class="pln">
</span><span class="pun">}];</span><span class="pln">

</span><span class="com">// 初始化标签页管理器</span><span class="pln">
$</span><span class="pun">(</span><span class="str">'#tabsExample'</span><span class="pun">).</span><span class="pln">tabs</span><span class="pun">({</span><span class="pln">tabs</span><span class="pun">:</span><span class="pln"> tabs</span><span class="pun">});</span></code></pre></article></section>


<section>
  <header><h3>选项</h3></header>
  <article><div class="table-responsive">
    <table class="table table-bordered">
  <thead>
    <tr>
      <th style="width: 140px">选项</th>
      <th style="width: 150px">名称</th>
      <th style="width: 150px">可用值</th>
      <th>说明</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><code>tabs</code></td>
      <td>初始标签页列表</td>
      <td>默认为 <code>[]</code></td>
      <td>指定一个标签页对象数组用于定义在标签页管理器初始化后显示的标签页，标签页对象定义参加下文。</td>
    </tr>
    <tr>
      <td><code>defaultTab</code></td>
      <td>默认激活的标签页 ID</td>
      <td>默认为 <code>null</code></td>
      <td>如果设置为空值（<code>null</code>）则会在标签页管理器初始化之后激活初始标签页列表中的第一个标签页。</td>
    </tr>
    <tr>
      <td><code>contextMenu</code></td>
      <td>是否启用上下文菜单</td>
      <td>默认为 <code>true</code></td>
      <td>如果设置为 <code>true</code> 则在导航上启用上下文菜单方便用户操作标签页，当使用鼠标操作时，通常是点击鼠标右键显示一个菜单。</td>
    </tr>
    <tr>
      <td><code>defaultTabIcon</code></td>
      <td>默认标签页图标</td>
      <td>默认为 <code>'icon-window'</code></td>
      <td>使用 <a href="'#control/icon'">控件-&gt;图标</a> 中的图标类名来设置标签页的图标。如果标签页对象中没有指定标签页图标属性则使用此选项作为默认图标。</td>
    </tr>
    <tr>
      <td><code>showMessage</code></td>
      <td>是否显示错误消息</td>
      <td>默认为 <code>true</code></td>
      <td></td>
    </tr>
    <tr>
      <td><code>errorTemplate</code></td>
      <td>错误消息模板字符串</td>
      <td>默认为 <code>'&lt;div class="alert alert-block alert-danger with-icon"&gt;&lt;i class="icon-warning-sign"&gt;&lt;/i&gt;&lt;div class="content"&gt;{0}&lt;/div&gt;&lt;/div&gt;'</code></td>
      <td></td>
    </tr>
    <tr>
      <td><code>messagerOptions</code></td>
      <td>弹出消息选项</td>
      <td><code>null</code></td>
      <td>当显示弹出消息时，可以使用此选项定一个对象用于设置<a href="javascript/messager">弹出消息</a>参数。</td>
    </tr>
    <tr>
      <td><code>lang</code></td>
      <td>当前界面语言</td>
      <td>默认为 <code>'zh_cn'</code></td>
      <td>
        <p>所以可用的选项包括：</p>
        <ul>
          <li><code>zh_cn</code>：使用中文简体界面；</li>
          <li><code>zh_tw</code>：使用中文繁体界面；</li>
          <li><code>en</code>：使用英文界面；</li>
          <li>
            <p>或者指定一个对象来自定义语言文本，例如：</p>
            <pre class="prettyprint prettyprinted" style=""><code><span class="pun">{</span><span class="pln">
    reload</span><span class="pun">:</span><span class="pln"> </span><span class="str">'重新加载'</span><span class="pun">,</span><span class="pln">
    close</span><span class="pun">:</span><span class="pln"> </span><span class="str">'关闭'</span><span class="pun">,</span><span class="pln">
    closeOthers</span><span class="pun">:</span><span class="pln"> </span><span class="str">'关闭其他标签页'</span><span class="pun">,</span><span class="pln">
    closeRight</span><span class="pun">:</span><span class="pln"> </span><span class="str">'关闭右侧标签页'</span><span class="pun">,</span><span class="pln">
    reopenLast</span><span class="pun">:</span><span class="pln"> </span><span class="str">'恢复上次关闭的标签页'</span><span class="pun">,</span><span class="pln">
    errorCannotFetchFromRemote</span><span class="pun">:</span><span class="pln"> </span><span class="str">'无法从远程服务器（{0}）获取内容。'</span><span class="pln">
</span><span class="pun">}</span></code></pre>
          </li>
        </ul>
      </td>
    </tr>
  </tbody>
</table></div></article></section>



<section><header><h3>标签页对象</h3></header><article><p>每个标签页使用一个对象来存储相关信息，通过定义一个标签页对象数组在初始化时传递给初始化函数来定义标签页管理器上的默认标签，当需要动态打开一个标签页时也需要定义标签页对象。标签页对象支持的属性包括：</p><div class="table-responsive"><table class="table table-bordered">
  <thead>
    <tr>
      <th style="width: 140px">选项</th>
      <th style="width: 150px">名称</th>
      <th style="width: 150px">可用值</th>
      <th>说明</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><code>id</code></td>
      <td>标签页的唯一标识</td>
      <td>默认自动生成</td>
      <td>一般不需要指定，如果需要自己管理标签对象，则需要设置一个全局唯一的字符串用于下次获取标签页对象。</td>
    </tr>
    <tr>
      <td><code>type</code></td>
      <td>标签页内容类型</td>
      <td>默认为 <code>'auto'</code></td>
      <td>
        <p>所有可用值包括</p>
        <ul>
          <li><code>'iframe'</code>：使用 iframe 来加载远程页面；</li>
          <li><code>'ajax'</code>：使用 ajax 来加载远程内容；</li>
          <li><code>'custom'</code>：使用 <code>content</code> 属性的值做为内容，如果 <code>content</code> 属性为函数则使用函数返回值作为内容；</li>
          <li><code>'auto'</code>：自动根据其他属性决定，如果设置了 <code>url</code> 属性且设置了 <code>ajax</code> 属性则为 <code>ajax</code>，否则则为 <code>iframe</code> 类型，如果没有设置 <code>url</code> 属性为 <code>custom</code> 类型。</li>
        </ul>
      </td>
    </tr>
    <tr>
      <td><code>url</code></td>
      <td>远程内容地址</td>
      <td>默认 <code>''</code></td>
      <td>当 <code>type</code> 属性为 <code>iframe</code> 时，此地址为远程页面地址，当 <code>type</code> 为 <code>ajax</code>，此地址作为远程内容请求地址。</td>
    </tr>
    <tr>
      <td><code>ajax</code></td>
      <td>ajax 请求参数</td>
      <td>默认 <code>{type: 'GET'}</code></td>
      <td>可以使用一个对象来定义 jQuery 的 Ajax 请求参数。</td>
    </tr>
    <tr>
      <td><code>icon</code></td>
      <td>标签页图标</td>
      <td>默认为 <code>'icon-window'</code></td>
      <td>使用 <a href="'#control/icon'">控件-&gt;图标</a> 中的图标类名来设置标签页的图标。默认为 <code>'icon-window'</code>，此默认值可以使用选项 <code>defaultTabIcon</code> 进行设置。</td>
    </tr>
    <tr>
      <td><code>title</code></td>
      <td>标签页标题</td>
      <td>默认为 <code>''</code></td>
      <td>当标签页标题设置为空 <code>''</code> 且标签页类型(<code>type</code>) 为 <code>'iframe'</code> 时会尝试从iframe页面中获取页面标题作为标签页标题。</td>
    </tr>
    <tr>
      <td><code>defaultTitle</code></td>
      <td>标签页默认标题</td>
      <td>默认为 <code>''</code></td>
      <td>当标签页标题设置为空 <code>''</code> 且标签页类型(<code>type</code>) 为 <code>'iframe'</code> 时会尝试从iframe页面中获取页面标题作为标签页标题，如果标签页还没有加载时会使用默认标题。</td>
    </tr>
    <tr>
      <td><code>forbidClose</code></td>
      <td>是否禁止标签页被手动关闭</td>
      <td>默认为 <code>false</code></td>
      <td>如果设置为 <code>true</code>，则不允许用户关闭此标签页。</td>
    </tr>
    <tr>
      <td><code>onCreate</code></td>
      <td>当标签页创建后的回调函数</td>
      <td>默认为 <code>null</code></td>
      <td>此回调函数包含一个参数为标签页对象。</td>
    </tr>
    <tr>
      <td><code>onOpen</code></td>
      <td>当标签页打开时的回调函数</td>
      <td>默认为 <code>null</code></td>
      <td>此回调函数包含一个参数为标签页对象。</td>
    </tr>
    <tr>
      <td><code>onClose</code></td>
      <td>当标签页关闭时的回调函数</td>
      <td>默认为 <code>null</code></td>
      <td>此回调函数包含一个参数为标签页对象。</td>
    </tr>
    <tr>
      <td><code>createTime</code>（只读）</td>
      <td>标签页对象创建的时间戳</td>
      <td>默认为 <code>0</code></td>
      <td>当标签页在管理器中创建后可以通过此属性来获取标签页对象创建的时间戳。</td>
    </tr>
    <tr>
      <td><code>openTime</code>（只读）</td>
      <td>标签页上次打开的时间戳</td>
      <td>默认为 <code>0</code></td>
      <td>当标签页在管理器中创建后可以通过此属性来获取标签页上次打开的时间戳。</td>
    </tr>
    <tr>
      <td><code>loaded</code>（只读）</td>
      <td>标签页上次内容加载的时间戳</td>
      <td>默认为 <code>0</code></td>
      <td>当标签页在管理器中创建后可以通过此属性来获取标签页上次内容加载的时间戳。</td>
    </tr>
  </tbody>
</table></div></article></section>

<section><header><h3>方法</h3></header><article><h4><code>open(tab)</code></h4><p>打开并激活一个标签页，如果此标签页是首次打开，则打开后自动加载标签页内容。此方法参数定义：</p><ul>
<li><code>tab</code>：标签页对象，或者使用一个远程服务器地址字符串作为参数自动创建一个标签页对象；</li>
<li><code>forceReload</code>：可选参数，如果设置为 <code>true</code>，则强制标签页重新加载内容，即使标签页内容已经加载过，相当于重新载入（刷新）功能。</li>
</ul><pre class="prettyprint prettyprinted" style=""><code class="lang-js"><span class="com">// 获取标签页管理器对象实例</span><span class="pln">
</span><span class="kwd">var</span><span class="pln"> myTabs </span><span class="pun">=</span><span class="pln"> $</span><span class="pun">(</span><span class="str">'#myTabs'</span><span class="pun">).</span><span class="pln">data</span><span class="pun">(</span><span class="str">'zui.tabs'</span><span class="pun">);</span><span class="pln">

</span><span class="com">// 要打开的标签页对象</span><span class="pln">
</span><span class="kwd">var</span><span class="pln"> myTab </span><span class="pun">=</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
    url</span><span class="pun">:</span><span class="pln"> </span><span class="str">'http://zui.sexy'</span><span class="pun">,</span><span class="pln">
    type</span><span class="pun">:</span><span class="pln"> </span><span class="str">'iframe'</span><span class="pun">,</span><span class="pln">
    defaultTitle</span><span class="pun">:</span><span class="pln"> </span><span class="str">'ZUI 官方网站'</span><span class="pln">
</span><span class="pun">};</span><span class="pln">
</span><span class="com">// 打开标签页</span><span class="pln">
myTabs</span><span class="pun">.</span><span class="pln">open</span><span class="pun">(</span><span class="pln">myTab</span><span class="pun">);</span></code></pre><pre class="prettyprint prettyprinted" style=""><code class="lang-js"><span class="com">// 当标签页类型为 iframe 时，还可以直接使用 iframe 地址作为参数</span><span class="pln">
myTabs</span><span class="pun">.</span><span class="pln">open</span><span class="pun">(</span><span class="str">'http://zui.sexy'</span><span class="pun">);</span></code></pre><h4><code>close(tabId, forceClose)</code></h4><p>关闭标签页。此方法参数定义：</p><ul>
<li><code>tabId</code>：要关闭的标签对象 ID 值；</li>
<li><code>forceClose</code>：可选参数，如果设置为 <code>true</code>，则强制关闭强制关闭标签页，即使标签页属性 <code>forbidClose</code> 被设置为 <code>true</code>。</li>
</ul><pre class="prettyprint prettyprinted" style=""><code class="lang-js"><span class="com">// 获取标签页管理器对象实例</span><span class="pln">
</span><span class="kwd">var</span><span class="pln"> myTabs </span><span class="pun">=</span><span class="pln"> $</span><span class="pun">(</span><span class="str">'#myTabs'</span><span class="pun">).</span><span class="pln">data</span><span class="pun">(</span><span class="str">'zui.tabs'</span><span class="pun">);</span><span class="pln">

</span><span class="com">// 关闭标签页</span><span class="pln">
myTabs</span><span class="pun">.</span><span class="pln">close</span><span class="pun">(</span><span class="str">'myCloseTabId'</span><span class="pun">);</span></code></pre><h4><code>getTab(tabId)</code></h4><p>根据标签页 ID 获取标签页对象。此方法参数定义：</p><ul>
<li><code>tabId</code>：要获取的标签对象 ID 值。</li>
</ul><pre class="prettyprint prettyprinted" style=""><code class="lang-js"><span class="com">// 获取标签页管理器对象实例</span><span class="pln">
</span><span class="kwd">var</span><span class="pln"> myTabs </span><span class="pun">=</span><span class="pln"> $</span><span class="pun">(</span><span class="str">'#myTabs'</span><span class="pun">).</span><span class="pln">data</span><span class="pun">(</span><span class="str">'zui.tabs'</span><span class="pun">);</span><span class="pln">

</span><span class="com">// 获取当前激活的标签页对象</span><span class="pln">
</span><span class="kwd">var</span><span class="pln"> mySpecialTab </span><span class="pun">=</span><span class="pln"> myTabs</span><span class="pun">.</span><span class="pln">getTab</span><span class="pun">(</span><span class="str">'mySpecialTabId'</span><span class="pun">);</span><span class="pln">
console</span><span class="pun">.</span><span class="pln">log</span><span class="pun">(</span><span class="str">'获取的签页标题为'</span><span class="pun">,</span><span class="pln"> mySpecialTab</span><span class="pun">.</span><span class="pln">title</span><span class="pun">);</span></code></pre><h4><code>getActiveTab()</code></h4><p>获取当前激活的标签页对象。</p><pre class="prettyprint prettyprinted" style=""><code class="lang-js"><span class="com">// 获取标签页管理器对象实例</span><span class="pln">
</span><span class="kwd">var</span><span class="pln"> myTabs </span><span class="pun">=</span><span class="pln"> $</span><span class="pun">(</span><span class="str">'#myTabs'</span><span class="pun">).</span><span class="pln">data</span><span class="pun">(</span><span class="str">'zui.tabs'</span><span class="pun">);</span><span class="pln">

</span><span class="com">// 获取当前激活的标签页对象</span><span class="pln">
</span><span class="kwd">var</span><span class="pln"> myActiveTab </span><span class="pun">=</span><span class="pln"> myTabs</span><span class="pun">.</span><span class="pln">getActiveTab</span><span class="pun">();</span><span class="pln">
console</span><span class="pun">.</span><span class="pln">log</span><span class="pun">(</span><span class="str">'当前激活的标签页标题为'</span><span class="pun">,</span><span class="pln"> myActiveTab</span><span class="pun">.</span><span class="pln">title</span><span class="pun">);</span></code></pre><h4><code>reload(tab)</code></h4><p>重新载入标签页内容。此方法参数定义：</p><ul>
<li><code>tab</code>：要重新载入的标签页对象，如果不指定此参数则重新载入当前激活的标签页。</li>
</ul><pre class="prettyprint prettyprinted" style=""><code class="lang-js"><span class="com">// 获取标签页管理器对象实例</span><span class="pln">
</span><span class="kwd">var</span><span class="pln"> myTabs </span><span class="pun">=</span><span class="pln"> $</span><span class="pun">(</span><span class="str">'#myTabs'</span><span class="pun">).</span><span class="pln">data</span><span class="pun">(</span><span class="str">'zui.tabs'</span><span class="pun">);</span><span class="pln">

</span><span class="com">// 重新载入当前激活的标签页</span><span class="pln">
myTabs</span><span class="pun">.</span><span class="pln">reload</span><span class="pun">();</span><span class="pln">

</span><span class="com">// 获取要载入的标签页对象</span><span class="pln">
</span><span class="kwd">var</span><span class="pln"> myTab </span><span class="pun">=</span><span class="pln"> myTabs</span><span class="pun">.</span><span class="pln">getTab</span><span class="pun">(</span><span class="str">'reloadTabId'</span><span class="pun">);</span><span class="pln">

</span><span class="com">// 重新载入标签页</span><span class="pln">
myTabs</span><span class="pun">.</span><span class="pln">reload</span><span class="pun">(</span><span class="pln">myTab</span><span class="pun">);</span></code></pre><h4><code>closeOthers(tabId)</code></h4><p>关闭当前标签页之外的其他标签页。该方法参数定义：</p><p><code>tabId</code>：当前标签页ID。</p><pre class="prettyprint prettyprinted" style=""><code class="lang-js"><span class="com">// 获取标签页管理器对象实例</span><span class="pln">
</span><span class="kwd">var</span><span class="pln"> myTabs </span><span class="pun">=</span><span class="pln"> $</span><span class="pun">(</span><span class="str">'#myTabs'</span><span class="pun">).</span><span class="pln">data</span><span class="pun">(</span><span class="str">'zui.tabs'</span><span class="pun">);</span><span class="pln">

</span><span class="com">// 关闭当前标签页之外的其他标签页</span><span class="pln">
myTabs</span><span class="pun">.</span><span class="pln">closeOthers</span><span class="pun">(</span><span class="str">'tabID'</span><span class="pun">);</span></code></pre><h4><code>closeRight(tabId)</code></h4><p>关闭导航上当前标签页右侧的标签页。该方法参数定义：</p><p><code>tabId</code>：当前标签页ID。</p><pre class="prettyprint prettyprinted" style=""><code class="lang-js"><span class="com">// 获取标签页管理器对象实例</span><span class="pln">
</span><span class="kwd">var</span><span class="pln"> myTabs </span><span class="pun">=</span><span class="pln"> $</span><span class="pun">(</span><span class="str">'#myTabs'</span><span class="pun">).</span><span class="pln">data</span><span class="pun">(</span><span class="str">'zui.tabs'</span><span class="pun">);</span><span class="pln">

</span><span class="com">// 关闭导航上当前标签页右侧的标签页</span><span class="pln">
myTabs</span><span class="pun">.</span><span class="pln">closeRight</span><span class="pun">(</span><span class="str">'tabID'</span><span class="pun">);</span></code></pre><h4><code>closeAll()</code></h4><p>关闭导航所有标签页。</p><pre class="prettyprint prettyprinted" style=""><code class="lang-js"><span class="com">// 获取标签页管理器对象实例</span><span class="pln">
</span><span class="kwd">var</span><span class="pln"> myTabs </span><span class="pun">=</span><span class="pln"> $</span><span class="pun">(</span><span class="str">'#myTabs'</span><span class="pun">).</span><span class="pln">data</span><span class="pun">(</span><span class="str">'zui.tabs'</span><span class="pun">);</span><span class="pln">

</span><span class="com">// 关闭所有标签页</span><span class="pln">
myTabs</span><span class="pun">.</span><span class="pln">closeAll</span><span class="pun">();</span></code></pre><h4><code>reopen()</code></h4><p>重新打开上次关闭的标签页。</p><pre class="prettyprint prettyprinted" style=""><code class="lang-js"><span class="com">// 获取标签页管理器对象实例</span><span class="pln">
</span><span class="kwd">var</span><span class="pln"> myTabs </span><span class="pun">=</span><span class="pln"> $</span><span class="pun">(</span><span class="str">'#myTabs'</span><span class="pun">).</span><span class="pln">data</span><span class="pun">(</span><span class="str">'zui.tabs'</span><span class="pun">);</span><span class="pln">

</span><span class="com">// 重新打开上次关闭的标签页</span><span class="pln">
myTabs</span><span class="pun">.</span><span class="pln">reopen</span><span class="pun">();</span></code></pre></article></section>




<section><header><h3>事件</h3></header><article><h4><code>onOpen</code></h4><p>当标签页被打开时触发。事件回调函数 <code>this</code> 为当前标签页管理器实例，参数定义如下：</p><ul>
<li><code>tab</code>：当前被打开的标签页对象。</li>
</ul><pre class="prettyprint prettyprinted" style=""><code class="lang-js"><span class="com">// 在初始化的时候设置事件回调函数</span><span class="pln">
$</span><span class="pun">(</span><span class="str">'#myTabs'</span><span class="pun">).</span><span class="pln">tabs</span><span class="pun">({</span><span class="pln">
    onOpen</span><span class="pun">:</span><span class="pln"> </span><span class="kwd">function</span><span class="pun">(</span><span class="pln">tab</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
        console</span><span class="pun">.</span><span class="pln">log</span><span class="pun">(</span><span class="str">'标签页 '</span><span class="pln"> </span><span class="pun">+</span><span class="pln"> tab</span><span class="pun">.</span><span class="pln">title </span><span class="pun">+</span><span class="pln"> </span><span class="str">' 被打开了。'</span><span class="pun">);</span><span class="pln">
    </span><span class="pun">}</span><span class="pln">
</span><span class="pun">});</span></code></pre><pre class="prettyprint prettyprinted" style=""><code class="lang-js"><span class="com">// 使用 jquery 的 $().on() 方法监听事件</span><span class="pln">
$</span><span class="pun">(</span><span class="str">'#myTabs'</span><span class="pun">).</span><span class="pln">on</span><span class="pun">(</span><span class="str">'onOpen'</span><span class="pun">,</span><span class="pln"> </span><span class="kwd">function</span><span class="pun">(</span><span class="pln">event</span><span class="pun">,</span><span class="pln"> tab</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
    console</span><span class="pun">.</span><span class="pln">log</span><span class="pun">(</span><span class="str">'标签页 '</span><span class="pln"> </span><span class="pun">+</span><span class="pln"> tab</span><span class="pun">.</span><span class="pln">title </span><span class="pun">+</span><span class="pln"> </span><span class="str">' 被打开了。'</span><span class="pun">);</span><span class="pln">
</span><span class="pun">});</span></code></pre><h4><code>onLoad</code></h4><p>当标签页加载完成时触发。事件回调函数 <code>this</code> 为当前标签页管理器实例，参数定义如下：</p><ul>
<li><code>tab</code>：当前加载完成的标签页对象。</li>
</ul><pre class="prettyprint prettyprinted" style=""><code class="lang-js"><span class="com">// 在初始化的时候设置事件回调函数</span><span class="pln">
$</span><span class="pun">(</span><span class="str">'#myTabs'</span><span class="pun">).</span><span class="pln">tabs</span><span class="pun">({</span><span class="pln">
    onLoad</span><span class="pun">:</span><span class="pln"> </span><span class="kwd">function</span><span class="pun">(</span><span class="pln">tab</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
        console</span><span class="pun">.</span><span class="pln">log</span><span class="pun">(</span><span class="str">'标签页 '</span><span class="pln"> </span><span class="pun">+</span><span class="pln"> tab</span><span class="pun">.</span><span class="pln">title </span><span class="pun">+</span><span class="pln"> </span><span class="str">' 加载完成了。'</span><span class="pun">);</span><span class="pln">
    </span><span class="pun">}</span><span class="pln">
</span><span class="pun">});</span></code></pre><pre class="prettyprint prettyprinted" style=""><code class="lang-js"><span class="com">// 使用 jquery 的 $().on() 方法监听事件</span><span class="pln">
$</span><span class="pun">(</span><span class="str">'#myTabs'</span><span class="pun">).</span><span class="pln">on</span><span class="pun">(</span><span class="str">'onLoad'</span><span class="pun">,</span><span class="pln"> </span><span class="kwd">function</span><span class="pun">(</span><span class="pln">event</span><span class="pun">,</span><span class="pln"> tab</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
    console</span><span class="pun">.</span><span class="pln">log</span><span class="pun">(</span><span class="str">'标签页 '</span><span class="pln"> </span><span class="pun">+</span><span class="pln"> tab</span><span class="pun">.</span><span class="pln">title </span><span class="pun">+</span><span class="pln"> </span><span class="str">' 加载完成了。'</span><span class="pun">);</span><span class="pln">
</span><span class="pun">});</span></code></pre><h4><code>onClose</code></h4><p>当标签页被关闭时触发。事件回调函数 <code>this</code> 为当前标签页管理器实例，参数定义如下：</p><ul>
<li><code>tab</code>：当前被关闭的标签页对象。</li>
</ul><pre class="prettyprint prettyprinted" style=""><code class="lang-js"><span class="com">// 在初始化的时候设置事件回调函数</span><span class="pln">
$</span><span class="pun">(</span><span class="str">'#myTabs'</span><span class="pun">).</span><span class="pln">tabs</span><span class="pun">({</span><span class="pln">
    onClose</span><span class="pun">:</span><span class="pln"> </span><span class="kwd">function</span><span class="pun">(</span><span class="pln">tab</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
        console</span><span class="pun">.</span><span class="pln">log</span><span class="pun">(</span><span class="str">'标签页 '</span><span class="pln"> </span><span class="pun">+</span><span class="pln"> tab</span><span class="pun">.</span><span class="pln">title </span><span class="pun">+</span><span class="pln"> </span><span class="str">' 被关闭了。'</span><span class="pun">);</span><span class="pln">
    </span><span class="pun">}</span><span class="pln">
</span><span class="pun">});</span></code></pre><pre class="prettyprint prettyprinted" style=""><code class="lang-js"><span class="com">// 使用 jquery 的 $().on() 方法监听事件</span><span class="pln">
$</span><span class="pun">(</span><span class="str">'#myTabs'</span><span class="pun">).</span><span class="pln">on</span><span class="pun">(</span><span class="str">'onClose'</span><span class="pun">,</span><span class="pln"> </span><span class="kwd">function</span><span class="pun">(</span><span class="pln">event</span><span class="pun">,</span><span class="pln"> tab</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
    console</span><span class="pun">.</span><span class="pln">log</span><span class="pun">(</span><span class="str">'标签页 '</span><span class="pln"> </span><span class="pun">+</span><span class="pln"> tab</span><span class="pun">.</span><span class="pln">title </span><span class="pun">+</span><span class="pln"> </span><span class="str">' 被关闭了。'</span><span class="pun">);</span><span class="pln">
</span><span class="pun">});</span></code></pre></article></section>

<script src="__ZUI__/lib/tabs/zui.tabs.js"></script>
<script>
$(function(){
	$('#tabsExample').tabs({
        tabs: [{
            title: 'iframe 例子',
            url: "{:url('iframe_tab')}",
            type: 'iframe',
            forbidClose: true
        }, {
            title: 'Ajax 例子',
            url: "{:url('remote_tab')}",
            type: 'ajax'
        }, {
            title: '自定义例子',
            icon: 'icon-star',
            type: 'custom',
            content: function() {
                return '<div class="alert alert-block alert-success"><p>这里的内容是通过函数动态生成的，每次刷新下面的时间都会更新。</p><p>' + (new Date().format('yyyy-MM-dd hh:mm:ss')) +   '</p></div>';
            }
        }, {
            title: 'MZUI',
            url: 'http://zui.sexy/m',
            type: 'iframe'
        }, {
            defaultTitle: '无法加载的标签页',
            url: 'http://zui1.sexy'
        }]
    });
});

</script>

<section>
  <header>
    <h3>自定义</h3>
  </header>
  <article><p>在标签页初始化元素中可以使用 <code>.tabs-navbar</code> 元素和 <code>.tabs-container</code> 元素来自定义导航和标签页内容的父级元素。</p><pre class="prettyprint prettyprinted" style=""><code class="lang-html"><span class="tag">&lt;div</span><span class="pln"> </span><span class="atn">id</span><span class="pun">=</span><span class="atv">"myTabs"</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"tabs"</span><span class="tag">&gt;</span><span class="pln">
  </span><span class="tag">&lt;nav</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"tabs-navbar"</span><span class="tag">&gt;&lt;/nav&gt;</span><span class="pln">
  </span><span class="tag">&lt;nav</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"tabs-container"</span><span class="tag">&gt;&lt;/nav&gt;</span><span class="pln">
</span><span class="tag">&lt;/div&gt;</span></code></pre>


</article>
</section>
</div>
</section>
{/block}